import request from '@/config/axios'

export interface FilePageReqVO extends PageParam {
  path?: string
  type?: string
  createTime?: Date[]
}
export interface DirVO {
  id?: number
  typeName?: string
  name: string
  parentId: number
  status: number
  sort: number
  createTime: Date
}
// 文件预签名地址 Response VO
export interface FilePresignedUrlRespVO {
  // 文件配置编号
  configId: number
  // 文件上传 URL
  uploadUrl: string
  // 文件 URL
  url: string
}
export interface fileExchangeVO {
  // 文件关联分类编号
  typeId: string
  // 文件编号数组
  ids: string
}

// 查询文件列表
export const getFilePage = (params: FilePageReqVO) => {
  return request.get({ url: '/infra/file/page', params })
}

// 删除文件
export const deleteFile = (id: number) => {
  return request.delete({ url: '/infra/file/delete?id=' + id })
}

// 获取文件预签名地址
export const getFilePresignedUrl = (path: string) => {
  return request.get<FilePresignedUrlRespVO>({
    url: '/infra/file/presigned-url',
    params: { path }
  })
}

// 创建文件
export const createFile = (data: any) => {
  return request.post({ url: '/infra/file/create', data })
}

// 上传文件
export const updateFile = (data: any) => {
  return request.upload({ url: '/infra/file/upload', data })
}
// 查询目录（精简)列表 simple-list 改为list
export const getSimpleDirList = async (): Promise<DirVO[]> => {
  return await request.get({ url: '/infra/types/list' })
}
// 查询目录列表
export const getDirPage = async () => {
  return await request.get({ url: '/infra/types/list' })
}

// 查询目录详情
export const getDir = async (id: number) => {
  return await request.get({ url: '/infra/types/get?id=' + id })
}

// 新增目录
export const createDir = async (data: DirVO) => {
  return await request.post({ url: '/infra/types/create', data: data })
}

// 修改目录
export const updateDir = async (params: DirVO) => {
  return await request.put({ url: '/infra/types/update', data: params })
}

// 删除目录
export const deleteDir = async (id: number) => {
  return await request.delete({ url: '/infra/types/delete?id=' + id })
}
// 更改文件目录
export const fileExchange = async (data: fileExchangeVO) => {
  return await request.post({ url: '/infra/file/exchange', data })
}
